#appendix - logits
#alan yan
#10-18-21

####setup####
rm(list = ls())

#load libraries
pacman::p_load(tidyverse,
               sandwich,
               lmtest,
               rms)

#load data
offensiveness.data <- read.csv("06-Pooled-Offensiveness/data/clean_data.csv")
silencing.data <- read.csv("03-Silencing-Study/data/01-clean-data/clean_data.csv")

####clean#### 
#dichotomize DVs
offensiveness.data %>% mutate(offensive_binary = offensive_binary/100) -> offensiveness.data
silencing.data %>% mutate(silenced = silenced/100,
                          responded = responded/100,
                          pure.silencing = pure.silencing/100,
                          withdrawal = withdrawal/100) -> silencing.data

####analysis ####
####*Table S22####
logit.offensive <- offensiveness.data %>%
  glm(offensive_binary ~ male + female + no.name, ., family = "binomial")
coeftest(logit.offensive, vcov = vcovHC(logit.offensive))
predict(logit.offensive, with(offensiveness.data, data.frame(female = c(0, 1, 0 , 0), 
                                                             male = c(0, 0, 1, 0), 
                                                             no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

ols.offensive <- offensiveness.data %>%
  lm(offensive_binary ~ female + male + no.name, .)
predict(ols.offensive, with(offensiveness.data, data.frame(female = c(0, 1, 0 , 0), 
                                                             male = c(0, 0, 1, 0), 
                                                             no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

logit.offensive.study1 <- offensiveness.data %>%
  filter(experiment1 == 1) %>%
  glm(offensive_binary ~ male + female + no.name, ., family = "binomial")
coeftest(logit.offensive.study1, vcov = vcovHC(logit.offensive.study1))
predict(logit.offensive.study1, with(offensiveness.data %>%
                                       filter(experiment1 == 1), data.frame(female = c(0, 1, 0 , 0), 
                                                             male = c(0, 0, 1, 0), 
                                                             no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

ols.offensive.study1 <- offensiveness.data %>%
  filter(experiment1 == 1) %>%
  lm(offensive_binary ~ female + male + no.name, .)
predict(ols.offensive.study1, with(offensiveness.data %>%
                                     filter(experiment1 == 1), data.frame(female = c(0, 1, 0 , 0), 
                                                           male = c(0, 0, 1, 0), 
                                                           no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

logit.offensive.study2 <- offensiveness.data %>%
  filter(experiment1 == 0) %>%
  glm(offensive_binary ~ male + female + no.name, ., family = "binomial")
coeftest(logit.offensive.study2, vcov = vcovHC(logit.offensive.study2))
predict(logit.offensive.study2, with(offensiveness.data %>%
                                       filter(experiment1 == 0), data.frame(female = c(0, 1, 0 , 0), 
                                                                            male = c(0, 0, 1, 0), 
                                                                            no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

ols.offensive.study2 <- offensiveness.data %>%
  filter(experiment1 == 0) %>%
  lm(offensive_binary ~ female + male + no.name, .)
predict(ols.offensive.study2, with(offensiveness.data %>%
                                     filter(experiment1 ==01), data.frame(female = c(0, 1, 0 , 0), 
                                                                          male = c(0, 0, 1, 0), 
                                                                          no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

####*Table S23####
logit.silencing <- silencing.data %>%
  glm(pure.silencing ~ male + female + no.name, ., family = "binomial")
coeftest(logit.silencing, vcov = vcovHC(logit.silencing))
predict(logit.silencing, with(silencing.data, data.frame(female = c(0, 1, 0 , 0), 
                                                             male = c(0, 0, 1, 0), 
                                                             no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

ols.silencing <- silencing.data %>%
  lm(pure.silencing ~ male + female + no.name, .)
predict(ols.silencing, with(silencing.data, data.frame(female = c(0, 1, 0 , 0), 
                                                         male = c(0, 0, 1, 0), 
                                                         no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

logit.silencing.study1 <- silencing.data %>%
  filter(experiment1 == 1) %>%
  glm(pure.silencing ~ male + female + no.name, ., family = "binomial")
coeftest(logit.silencing.study1, vcov = vcovHC(logit.silencing.study1))
predict(logit.silencing.study1, with(silencing.data %>%
                                       filter(experiment1 == 1), data.frame(female = c(0, 1, 0 , 0), 
                                                         male = c(0, 0, 1, 0), 
                                                         no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

ols.silencing.study1 <- silencing.data %>%
  filter(experiment1 == 1) %>%
  lm(pure.silencing ~ male + female + no.name, .)
predict(ols.silencing.study1, with(silencing.data %>% 
                              filter(experiment1 == 1), data.frame(female = c(0, 1, 0 , 0), 
                                                       male = c(0, 0, 1, 0), 
                                                       no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

logit.silencing.study2 <- silencing.data %>%
  filter(experiment1 == 0) %>%
  glm(pure.silencing ~ male + female + no.name, ., family = "binomial")
coeftest(logit.silencing.study2, vcov = vcovHC(logit.silencing.study2))
predict(logit.silencing.study2, with(silencing.data %>%
                                       filter(experiment1 == 0), data.frame(female = c(0, 1, 0 , 0), 
                                                                            male = c(0, 0, 1, 0), 
                                                                            no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

ols.silencing.study2 <- silencing.data %>%
  filter(experiment1 == 0) %>%
  lm(pure.silencing ~ male + female + no.name, .)
predict(ols.silencing.study2, with(silencing.data %>%
                                     filter(experiment1 == 0), data.frame(female = c(0, 1, 0 , 0), 
                                                       male = c(0, 0, 1, 0), 
                                                       no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

####*Table S24####
logit.withdrawal <- silencing.data %>%
  glm(withdrawal ~ male + female + no.name, ., family = binomial())
coeftest(logit.withdrawal, vcov = vcovHC(logit.withdrawal))
predict(logit.withdrawal, with(silencing.data, data.frame(female = c(0, 1, 0 , 0), 
                                                          male = c(0, 0, 1, 0), 
                                                          no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

ols.withdrawal <- silencing.data %>%
  lm(withdrawal ~ male + female + no.name, .)
predict(ols.withdrawal, with(silencing.data, data.frame(female = c(0, 1, 0 , 0), 
                                                        male = c(0, 0, 1, 0), 
                                                        no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

logit.withdrawal.study1 <- silencing.data %>%
  filter(experiment1 == 1) %>%
  glm(withdrawal ~ male + female + no.name, ., family = "binomial")
coeftest(logit.withdrawal.study1, vcov = vcovHC(logit.withdrawal.study1))
predict(logit.withdrawal.study1, with(silencing.data %>%
                                        filter(experiment1 == 1), data.frame(female = c(0, 1, 0 , 0), 
                                                                             male = c(0, 0, 1, 0), 
                                                                             no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

ols.withdrawal.study1 <- silencing.data %>%
  filter(experiment1 == 1) %>%
  lm(withdrawal ~ male + female + no.name, .)
predict(ols.withdrawal.study1, with(silencing.data %>%
                                      filter(experiment1 == 1), data.frame(female = c(0, 1, 0 , 0), 
                                                                           male = c(0, 0, 1, 0), 
                                                                           no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

logit.withdrawal.study2 <- silencing.data %>%
  filter(experiment1 == 0) %>%
  glm(withdrawal ~ male + female + no.name, ., family = "binomial")
coeftest(logit.withdrawal.study2, vcov = vcovHC(logit.withdrawal.study2))
predict(logit.withdrawal.study2, with(silencing.data %>%
                                        filter(experiment1 == 0), data.frame(female = c(0, 1, 0 , 0), 
                                                                             male = c(0, 0, 1, 0), 
                                                                             no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

ols.withdrawal.study2 <- silencing.data %>%
  filter(experiment1 == 0) %>%
  lm(withdrawal ~ male + female + no.name, .)
predict(ols.withdrawal.study2, with(silencing.data %>%
                                      filter(experiment1 == 0), data.frame(female = c(0, 1, 0 , 0), 
                                                                           male = c(0, 0, 1, 0), 
                                                                           no.name = c(0, 0, 0, 1))), 
        type = "response",
        se = TRUE)

####*response rates####
silencing.data %>%
  glm(responded ~ male + female + no.name + experiment1, ., family = "binomial") %>%
  coeftest(., vcov = vcovHC(.))

silencing.data %>%
  filter(gender == "female") %>%
  glm(responded ~ male + female + no.name + experiment1, ., family = "binomial") %>%
  coeftest(., vcov = vcovHC(.))

silencing.data %>%
  filter(gender == "male") %>%
  glm(responded ~ male + female + no.name + experiment1, ., family = "binomial") %>%
  coeftest(., vcov = vcovHC(.))


